package fi.pakkanen.yarpg.core;

/**
 * The moving directions for movable creatures on the map.
 * 
 * @author Oliver Michels <oliver.michels@gmx.net>
 * 
 */
public enum MovingDirection {
	NORTH(-1, 0),
	NORTHEAST(-1, 1),
	EAST(0, 1),
	SOUTHEAST(1, 1),
	SOUTH(1, 0),
	SOUTHWEST(1, -1),
	WEST(0, -1),
	NORTHWEST(-1, -1);

	/** The position delta on the x-axis when moving to this direction */
	private final int deltaX;

	/** The position delta on the y-axis when moving to this direction */
	private final int deltaY;

	/**
	 * Create a new moving direction.
	 * 
	 * @param deltaX
	 * @param deltaY
	 */
	private MovingDirection(int deltaX, int deltaY) {
		this.deltaX = deltaX;
		this.deltaY = deltaY;
	}

	/**
	 * Move from a given position into a direction.
	 * 
	 * @param position
	 *            the starting position
	 * @return the new position
	 */
	public Position moveFrom(Position position) {
		return new Position(position.getMap(), position.getX() + deltaX, position.getY() + deltaY);
	}

}
